package org.xbzheng.sc.core.config;

import com.alibaba.druid.util.DruidPasswordCallback;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.xbzheng.sc.core.util.SecurityUtil;
import org.xbzheng.sc.exception.CryptoException;

import java.util.Properties;

/**
 * Created by Administrator on 2016/7/13.
 */
public class DBPasswordCallback extends DruidPasswordCallback {
    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        final String pwd = properties.getProperty("password");
        if(StringUtils.isNotBlank(pwd)){
            try{
                String password = SecurityUtil.aesDecrypt(pwd, "hun");
                setPassword(password.toCharArray());
            }catch (final CryptoException e){
                setPassword(pwd.toCharArray());
            }
        }
    }
}
